function fitting = FitMainField(~, signal, varargin)
    p = inputParser; p.KeepUnmatched = true;
    p.addRequired('range', @(x) isnumeric(x) && length(x) == 2);
    p.addParameter('initialField', 6.0, @(x) x>0);
    p.addParameter('isFixBz0', false, @islogical);
    p.parse(varargin{:});
        
    data = signal.getNodeData(1); bzList = data.x; signalList= data.y;
    
    x = bzList; 
    [maxY, pkIdx] = max(signalList);
    y2 = (signalList./maxY).^2;
    [xData, yData] = prepareCurveData( x, y2 );
    
    center0 = bzList(pkIdx);
    range_width = p.Results.range(2) - p.Results.range(1);
    excludeIdx = find( x<p.Results.range(1) | x>p.Results.range(2));

    if p.Results.isFixBz0
        rangeLeft = p.Results.initialField;
        center = p.Results.initialField;
        rangeRight = p.Results.initialField;
    else
        rangeLeft = p.Results.range(1);
        center = center0;
        rangeRight = p.Results.range(2);
    end

    ft = fittype( 'a*g*g/((x-x0)^2+g*g)', 'independent', 'x', 'dependent', 'y' );
    excludedPoints = excludedata( xData, yData, 'Indices', excludeIdx);
    opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
    opts.Display = 'Off';
    opts.Lower =      [0.5 0.0             rangeLeft];
    opts.StartPoint = [1.0 0.5*range_width center];
    opts.Upper =      [2.0 1.0*range_width rangeRight];
    opts.Exclude = excludedPoints;

    [fitting.result, fitting.gof] = fit( xData, yData, ft, opts );
    fitting.bz0 = fitting.result.x0;
    fitting.width = fitting.result.g;
    fitting.hight = sqrt(fitting.result.a)*maxY;
    fitting.range = p.Results.range;
    fitting.norm = maxY;
end